/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.Calendar;

/**
 * <p>Project: jse2204 - Switch3
 * <p>Powered by webrx On 2022-09-02 17:16:51
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Switch3 {
    public static void main(String[] args) {

        var c = Calendar.getInstance();
        int k = c.get(Calendar.DAY_OF_WEEK);
        String str = switch (k) {
            case 1 -> "星期日";
            case 2 -> "星期一";
            case 3 -> "星期二";
            case 4 -> "星期三";
            case 5 -> "星期四";
            case 6 -> "星期五";
            default -> "星期六";
        };
        System.out.println(str);

        //0-11
        var m = c.get(Calendar.MONTH) + 1;//1-12
        m = 2;

        c.set(Calendar.YEAR, 2008);


        System.out.println(m);
        int days = switch (m) {
            //case 2 -> LocalDate.of(c.get(1), m, 1).isLeapYear() ? 29 : 28;
            case 2 -> {
                int d = 28;
                if (c.get(1) % 400 == 0 || c.get(1) % 4 == 0 && c.get(1) % 100 != 0) {
                    d = 29;
                }
                yield d; //此处的yield 是返回值表达式的结果
            }
            case 4, 6, 9, 11 -> 30;
            default -> 31;
        };
        System.out.printf("%d年%d月有%d天。", c.get(1), m, days);
        System.out.println();
        System.out.println("=====================");

        switch (m) {
            case 2 -> System.out.printf("%d年%d月有%d天。", c.get(1), c.get(2), (c.get(1) % 400 == 0 || c.get(1) % 4 == 0 && c.get(1) % 100 != 0) ? 29 : 28);
            case 4, 6, 9, 11 -> System.out.printf("%d年%d月有%d天。", c.get(1), c.get(2), 30);
            default -> System.out.printf("%d年%d月有%d天。", c.get(1), c.get(2), 31);
        }

    }
}
